<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Reconciliation.ascx.vb" Inherits="WebForm_ManageReconciliation_Reconciliation" %>
<%@ Register Src="~/WebForm/ManageReconciliation/SearchOption.ascx" TagName="ProductHierarchyControl"
    TagPrefix="My" %>

<script type="text/javascript">
    function <%=Me.ClientID %>js_LoadCompleted(sheetid) {
        $get(sheetid).ActiveWindow.ActiveSheet.Protection.Enabled = false;
        $get(sheetid).Columns("A:P").AutoFit();
        $get(sheetid).activeSheet.cells.locked = true;
        $get(sheetid).ActiveWindow.ActiveSheet.Protection.Enabled = true;
    }
</script>

<script type="text/javascript" for="RC_Spreadsheet1" event="LoadCompleted()">
    <%=Me.ClientID %>js_LoadCompleted("RC_Spreadsheet1");
</script>

<My:ProductHierarchyControl ID="ProductHierarchyControl1" runat="server" />
<br />
<asp:PlaceHolder ID="pl1" runat="server" Visible="false">
    <div style="background-color: #351D26">
        <fieldset id="pnlData" runat="server" style="border-color: #4E333B;">
            <legend class="white2">
                <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:pnlData.GroupingText%>" />
            </legend>&nbsp;
        </fieldset>
    </div>
    <asp:HiddenField ID="RC_Spreadsheet1Data" runat="server" />
    <object id="RC_Spreadsheet1" classid="CLSID:0002E559-0000-0000-C000-000000000046"
        width="100%" height="600px" standby="Loading">
        <param name="DataType" value="XMLURL" />
        <param name="XMLURL" value="<%= Me.ReportXML %>" />
        <param name="AutoFit" value="0" />
    </object>

    <script type="text/vbscript">
    Sub RC_Spreadsheet1_SelectionChange()
        set WorkSheet_SS = document.getElementById("RC_Spreadsheet1")
        Dim Row 
	    Dim Col
	    MaxCol = WorkSheet_SS.ActiveSheet.UsedRange.Columns.Count 
        MaxRow = WorkSheet_SS.ActiveSheet.UsedRange.Rows.Count 
        sumvalue = 0 
        sumcount = 0 
        colType = "Number"
        for Each Row In WorkSheet_SS.Selection.Rows 
	        if Row.row > MaxRow then 
	            exit for 
            end if 
            for Each Col In WorkSheet_SS.Selection.Columns 
    	        if Col.column > MaxCol then 
 	 	            exit for 
                end if 
                if VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)>=2 and VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)<=5 then 
                    if sumcount=0 and InStr(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).NumberFormat,"%")<>0 then
                        colType = "Percent"
                    end if
                    if colType = "Percent" then 
                        sumvalue = sumvalue + (WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value * 100)
                    else
                        sumvalue = sumvalue + WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value 
                    end if
                    sumcount = sumcount + 1
                end if 
            next 
        next 

        if sumcount<>0 Then
            if colType = "Percent" then
                avg = Round(sumvalue / sumcount,2)
            else
                avg = Round(sumvalue / sumcount,0)
            end if
        else
            avg = 0
        end if
        if colType = "Percent" then
            window.status = "Average: " & FormatNumber(avg,2) & "%" & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,2) & "%"
        else
            window.status = "Average: " & FormatNumber(avg,0) & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,0)
        end if
        
    End Sub 
    </script>

</asp:PlaceHolder>
